<?php

namespace Portal\RateBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class RateController extends Controller
{
    public function indexAction($name)
    {
        return $this->render('PortalRateBundle:Rate:index.html.twig', array('name' => $name));
    }
    
    public function showRateAction($tutorId)
    {
        $user = $this->container->get('security.context')->getToken()->getUser();
        if(!$user)
        {
            $userId = null;
        }
        // check have ticket returns true, false
        $checkTicket = $this->getDoctrine()->getEntityManager()->getRepository('PortalRateBundle:Ticket')->checkTicket($userId, $tutorId);
        if($checkTicket === TRUE)
        {
            $isDisabled = FALSE;
        }else{
            $isDisabled = TRUE;
        }
        $rate = $this->getDoctrine()->getEntityManager()->getRepository('PortalRateBundle:Rate')->getCurrentRate($tutorId);
        return $this->render('PortalRateBundle:Rate:showRate.html.twig', array(
            'isDisabled' => $isDisabled,
            'rate' => $rate,
            'tutorId' => $tutorId
                
    ));
    }
}
